/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
export var nextGreaterElement = function (nums1, nums2) {
  const stack = []
  const map = new Map()
  for (let i = 0; i < nums2.length; i++) {
    const item = nums2[i]
    while (stack.length && stack[stack.length - 1] < item) {
      map.set(stack.pop(), item)
    }
    stack.push(item)
  }
  return nums1.map(item => map.get(item) || -1)
}
